<extend name="Public/base"/>
<block name="head">
    <link rel="stylesheet" href="__PUBLIC__/dist/css/bootstrapValidator.css"/>
    <link href="__PUBLIC__/fileinput/fileinput.css" rel="stylesheet" type="text/css" />
    <style>
        .mail-select {
            height: 36px !important;
            border: #ccc;
            color: #000;
            padding: 0px;
            background-color: #e7e7e7 !important;
            margin-top:6px;
        }
    </style>
</block>

<block name="body">
	<section class="section-sm">
        <div class="container-fluid">
          <div class="row">

            <div class="col-sm-12 col-md-8 col-md-offset-2">
                <div class="panel panel-default well ">

                <div class="panel-heading">
                    <h3 class="panel-title">{$Think.lang.Basic Settings}</h3>
                </div>
                <div class="panel-body">
                <form class="form-horizontal" action="__APP__/Index/saveProfile" enctype="multipart/form-data" method="post" id="editProfileForm" onsubmit="
                if(!hasMainEmailBox()){alert('至少需要一个主邮箱！');return false;}">
                <div class="form-group">
                  <label class="col-sm-3 control-label" for="avatar">{$Think.lang.Avatar}</label>
                  <div class="col-sm-9 sm-header">
                       <input class="form-control" type="file" class="file form-control" name="avatar" id="file_avatar" data-preview-file-type="text">
                  </div><!-- /.col -->
                </div>

                <div class="form-group ">
                  <label class="col-sm-3 control-label" for="public-name">{$Think.lang.Public Name}</label>
                  <div class="col-sm-9">
                    <input class="form-control" type="text" value="{$vo['nickname']}" name="nickname" class="required form-control" id="public-name" placeholder="Public name">
                  </div><!-- /.col -->
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label" for="user-email">{$Think.lang.Email}</label>
                    <div class="col-sm-9 email-form-group">
                        <volist name="emaillist" id="v">
                            <?php //$emailsufix = explode('@',$v['email']); ?>
                            <div class="email-item e-aa">
                                <div class="input-group col-md-8  col-lg-9 pull-left ">
                                    <input type="text" class="form-control" name="emailaddress[]" readonly value="{$v['email']}"  aria-label="...">
                                </div>
                                <!--<div class="input-group-btn e-mm" style="width: 130px !important;">-->
                                        <!--<select name="mailbox_suffix[]" class="form-control mail-select  mail-sufix " >-->
                                            <!--{$emailSuffix | renderOptions = $v['type_id'] == ''?'':$v['type_id']}-->
                                        <!--</select>-->
                                <!--</div>-->
                                <div class="input-group col-md-4 col-lg-3 pull-left e-dd">
                                    <div class="input-group-btn ">
                                        <select name="is_main[]" class="form-control mail-select mail-default">
                                            <option value="0" <?php if($v['is_main']==0): ?>selected<?php endif; ?>>次邮箱</option>
                                            <option value="1" <?php if($v['is_main']): ?>selected<?php endif; ?>>主邮箱</option>
                                        </select>
                                    </div>
                                    <a href="javascript:;"  data="{$v['id']}" class="btn button btn-default email-ajaxremove"><i class="fa fa-remove"></i></a>
                                </div>
                            </div>
                        </volist>
                    </div>
                    <!--<div class="col-md-12 text-right "><a href="javascript:;"  class="btn button btn-primary  email-add">{$Think.lang.Add}</a> </div>-->
                </div>

                <div class="form-group">
                  <label class="col-sm-3 control-label" for="user-password">{$Think.lang.Password}</label>
                  <div class="col-sm-9">
                      <a href="__APP__/Public/viaEmail" >
                        <button class="btn btn-block btn-primary" type="button">{$Think.lang.Retrieve password via email}</button>
                      </a>
                  </div><!-- /.col -->
                </div><!-- /.form-group -->


                <div class="form-group">
                  <label class="col-sm-3 control-label" for="user-bio">{$Think.lang.Brief Bio}</label>
                  <div class="col-sm-9">
                    <textarea class="form-control" rows="6" id="user-bio" name="remark" placeholder="Tell us about yourself" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 124px;">{$vo['remark']}</textarea>
                  </div><!-- /.col -->
                </div><!-- /.form-group -->

                <div class="form-group">
                    <div class="col-lg-9 col-lg-offset-3">
                        <div id="errors"></div>
                    </div>
                </div>
                <div class="form-group">
                  <div class="col-sm-offset-3 col-sm-9">
                    <button type="submit" class="btn btn-primary">{$Think.lang.Save}</button>
                  </div><!-- /.col -->
                </div><!-- /.form-group -->

                </form><!-- /.form-horizontal -->
                </div>

                </div>
            </div><!-- /.col -->
          </div><!-- /.row -->

        </div><!-- /.container -->
      </section>


</block>


<block name="script">

    <script src="__PUBLIC__/dist/js/bootstrapValidator.js" type="text/javascript"></script>
    <script src="__PUBLIC__/dist/js/language/zh_CN.js" type="text/javascript"></script>
    <script src="__PUBLIC__/dist/js/validator.js" type="text/javascript"></script>
    <script src='__PUBLIC__/fileinput/fileinput.js'></script>
    <script src='__PUBLIC__/fileinput/fileinput_locale_zh.js'></script>
    <script src="__PUBLIC__/dist/js/custom_email.js"></script>
    <script type="text/javascript">

        $(function () {

            var avatar =" <?php echo $vo['avatar'] == ''?'__PUBLIC__/dist/img/avatar5.png':$vo['avatar']; ?>"
            $("#file_avatar").fileinput({
                'allowedFileExtensions': ['jpg', 'png','gif'],
                initialPreview: ["<img src='"+avatar+"' class='file-preview-image' alt='Desert' title='Desert'>"]
            });

            Validator('editProfileForm','#errors');

            $('.email-ajaxremove').on('click', function () {
                if (confirm('确认该邮箱？')){
                    if (checkLastItem()){
                        if ($(this).prev().find('select').val() == 1){
                            alert('主邮箱不能删除！');
                            return;
                        }
                        var id = $(this).attr('data');
                        var then = $(this);
                        $.post('__APP__/Public/removeMailListItem',{
                            id : id
                        }).done(function(data){
                            if (data.status){
                                then.parents('.email-item').remove();
                                alert('删除成功！');
                            }else {
                                alert(data.info);
                            }
                        });
                    }else {
                        alert('至少存在一个邮箱！');
                    }

                }
            });
        });

    </script>

</block>